/*
 * Created on Dec 5, 2003
 *
 * To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
package org.vectrics.company.web.struts;

import java.util.Date;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.vectrics.provider.CoreServiceLocator;

public class CompanyPersonRoleForm extends ActionForm {

	private static final long serialVersionUID = 6051307250004339346L;
	
	private transient final Log log = LogFactory.getLog(this.getClass());
	private String personId = null;
	private String companyId = null;
	private String companyPersonRoleId = null;
	
	private String companyName = null;
	private String personName = null;
	private String title = null;
	private String dateStart = null;
	private String dateEnd = null;
	private String roleType = null;
	private String domainId = null;
	
	
	/**
	 * @return Returns the dateEnd.
	 */
	public String getDateEnd() {
		return dateEnd;
	}
	/**
	 * @param dateEnd The dateEnd to set.
	 */
	public void setDateEnd(String dateEnd) {
		this.dateEnd = dateEnd;
	}
	/**
	 * @return Returns the dateStart.
	 */
	public String getDateStart() {
		return dateStart;
	}
	/**
	 * @param dateStart The dateStart to set.
	 */
	public void setDateStart(String dateStart) {
		this.dateStart = dateStart;
	}
	/**
	 * @return Returns the personName.
	 */
	public String getPersonName() {
		return personName;
	}
	/**
	 * @param personName The personName to set.
	 */
	public void setPersonName(String personName) {
		this.personName = personName;
	}
	/**
	 * @return Returns the roleTypeCode.
	 */
	public String getRoleType() {
		return roleType;
	}
	/**
	 * @param roleTypeCode The roleTypeCode to set.
	 */
	public void setRoleType(String roleTypeCode) {
		this.roleType = roleTypeCode;
	}
	/**
	 * @return Returns the title.
	 */
	public String getTitle() {
		return title;
	}
	/**
	 * @param title The title to set.
	 */
	public void setTitle(String title) {
		this.title = title;
	}
    
	/**
	 * @return Returns the companyName.
	 */
	public String getCompanyName() {
		return companyName;
	}
	/**
	 * @param companyName The companyName to set.
	 */
	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}
	
	/*
	 * Validate data
	 */
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		Locale locale = request.getLocale();
		Date startDate = null;
		
		if (request.getParameter("cancel") == null) {
			if ((this.getDateStart() == null) || (this.getDateStart().trim().length() == 0)) {
				errors.add("DateStart", new ActionMessage("error.date.start.required"));
			} else {
				try {
					startDate = CoreServiceLocator.getDateFormat().getDateFormatRoundToDay(locale).parse(this.getDateStart());
				} catch (Exception ex) {
					errors.add("DateStart", new ActionMessage("error.date.start.format"));
				}
			}
			
			Date endDate = null;
			if ((this.getDateEnd() == null) || (this.getDateEnd().trim().length() == 0)) {
			} else {
				try {
					endDate = CoreServiceLocator.getDateFormat().getDateFormatRoundToDay(locale).parse(this.getDateEnd());
				} catch (Exception ex) {
					errors.add("DateEnd", new ActionMessage("error.date.end.format"));
				}
			}
		}
		return(errors);	
	}
	
	
	/**
	 * @return Returns the companyId.
	 */
	public String getCompanyId() {
		return companyId;
	}
	/**
	 * @param companyId The companyId to set.
	 */
	public void setCompanyId(String companyId) {
		this.companyId = companyId;
	}
	
	/**
	 * @return Returns the companyPersonRoleId.
	 */
	public String getCompanyPersonRoleId() {
		return companyPersonRoleId;
	}
	/**
	 * @param companyPersonRoleId The companyPersonRoleId to set.
	 */
	public void setCompanyPersonRoleId(String companyPersonRoleId) {
		this.companyPersonRoleId = companyPersonRoleId;
	}
	/**
	 * @return Returns the personId.
	 */
	public String getPersonId() {
		return personId;
	}
	/**
	 * @param personId The personId to set.
	 */
	public void setPersonId(String personId) {
		this.personId = personId;
	}
	/**
	 * @return Returns the domainId.
	 */
	public String getDomainId() {
		return domainId;
	}
	/**
	 * @param domainId The domainId to set.
	 */
	public void setDomainId(String domainId) {
		this.domainId = domainId;
	}

}
